<template>
  <div class="mt-4 w-auto pl-4 box-border">
    <div class="flex w-full items-end">
      <el-button type="primary" @click="handleAdd">新增</el-button>
    </div>

    <el-table class="mt-4" :data="tableData" border style="width:88vw">
      <el-table-column prop="id" label="序号" width="150px"></el-table-column>
      <el-table-column prop="name" label="特权名称"></el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="{ row }">
          <div>{{ row.status === 1 ? '启用' : '禁用' }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="icon_img" label="特权图标">
        <template slot-scope="{ row }">
          <el-popover placement="right" max-width="420" trigger="hover">
            <img :src="row.icon_img" alt="" style="max-width: 200px; max-height: 200px"/>
            <img slot="reference" :src="row.icon_img" alt="" style="width: 50px"/>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column prop="dark_icon_img" label="特权图标暗">
        <template slot-scope="{ row }">
          <el-popover placement="right" max-width="420" trigger="hover">
            <img :src="row.dark_icon_img" alt="" style="max-width: 200px; max-height: 200px"/>
            <img slot="reference" :src="row.dark_icon_img" alt="" style="width: 50px"/>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column prop="explain_img" label="特权图标说明图">
        <template slot-scope="{ row }">
          <el-popover placement="right" max-width="420" trigger="hover">
            <img :src="row.explain_img" alt="" style="max-width: 200px; max-height: 200px"/>
            <img slot="reference" :src="row.explain_img" alt="" style="width: 50px"/>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column prop="explain1" label="特权说明"></el-table-column>
      <el-table-column prop="explain2" label="特权说明2"></el-table-column>
      <el-table-column prop="type" label="特权类型"></el-table-column>
      <el-table-column prop="sort" label="排序"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" plain size="mini" icon="el-icon-edit" @click="deBounceWrap(handleEdit, scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <TMPagination
      :current-page.sync="pageList.page"
      :total.sync="pageList.total"
      :page-size.sync="pageList.page_size"
      @updateTable="getTableData"
    />

    <add-edit-modal :status.sync="model.status" :dialogVisible.sync="model.visible" :detail.sync="model.detail" @updateTable="getTableData"/>

  </div>
</template>

<script>

import { getTableData } from "@/api/dailyCheck/memberPrivilegeManagement";

import addEditModal from './childComps/addEditModel'
import TMPagination from "@/views/personalizedMall/wishList/childComps/TMPagination/TMPagination";

export default {
  name: "index",
  components: { TMPagination, addEditModal },
  data() {
    return {
      tableData: [],
      pageList: {
        page: 1,
        total: 10,
        page_size: 10
      },
      model: {
        visible: false,
        status: 'Add',
        detail: {}
      }
    }
  },
  created() {
    this.getTableData()
  },
  methods: {
    async getTableData() {
      const { data } = await getTableData(this.pageList.page, this.pageList.page_size)
      this.tableData = data.data
      this.pageList.total = data.total
      console.log(data)
    },
    // 新增
    handleAdd() {
      this.model.status = 'Add'
      this.model.visible = true
    },
    handleEdit(row) {
      this.model.detail = row
      this.model.status = 'Edit'
      this.model.visible = true
    }
  }
}
</script>

<style scoped lang="scss">

</style>
